#include <bits/stdc++.h>
using namespace std;
vector<int> getNext(string &pattern) {
  vector<int> next(pattern.size() + 1);
  int j = 0;

  for (int i = 1; i < pattern.size(); i++) {
    while (j > 0 && pattern.at(i) != pattern.at(j)) {
      j = next.at(j - 1);
    }

    if (pattern.at(i) == pattern.at(j)) {
      j++;
    }

    next.at(i) = j;
  }

  return next;
}
int strStr(string &text, string &pattern) {
  if (pattern.size() == 0) {
    return 0;
  }

  vector<int> next = getNext(pattern);
  int j = 0;
  for (int i = 1; i < text.size(); i++) {
    while (j > 0 && text.at(i) != pattern.at(j)) {
      j = next.at(j - 1);
    }

    if (text.at(i) == pattern.at(j)) {
      j++;
    }

    if (j == pattern.size()) {
      return (i - pattern.size() + 1);
    }
  }
}